<%--
  Created by IntelliJ IDEA.
  User: HW
  Date: 2018/4/19
  Time: 1:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<script type="text/javascript" src="../../js/jquery-1.11.0.js"></script>
<script type="text/javascript" src="../../js/jquery-migrate-1.2.1.js"></script>
<script src="../../js/jquery.js"></script>
<head>
    <title>乡镇图书管理系统</title>
</head>
<body style="background:cornflowerblue;height: 100%">
<div align="center">
    <table style="width: auto" border="1">
        <thead>
        <tr>
            <td align="center" colspan="4">
                <h1>乡镇图书管理系统</h1>
            </td>
        </tr>
        </thead>
        <tr>
            <td>
                <form>
                    <input id="typeId" type="hidden" name="typeId"/>
                    <p>图书类型<input list="typelist" id="typeName" name="typeName"/></p>
                    <p style="text-align: center;width: 100%"><input type="submit" value="提交" onclick="ifupdate(this.form)"></p>
                </form>
            </td>
        </tr>
        <datalist id="typelist">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
        </datalist>
    </table>
</div>
</body>
<script type="text/javascript">
    window.onload = function() {
        $("#typeName").val("<%=request.getAttribute("typeName")%>");
        $("#typeId").val("<%=request.getAttribute("typeId")%>")
    }

    function ifupdate(form) {
        var updatestate=confirm("确定更改？");
        if(updatestate){
            $.ajax({
                type:"post",
                url:"/book/updateType",
                dataType:"json",
                data:{
                    typeName:$("#typeName").val(),
                    typeId:$("#typeId").val()
                },
                success:function (data) {
                    if(data==1){
                        alert("更新成功");
                    }else {
                        alert("更新失败");
                    }
                }
            })
        }

    }
</script>
</html>
